package com.modbus.tool.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.modbus.tool.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.modbus.tool.service.IDeviceService;
import com.modbus.tool.entity.po.Device;

import org.springframework.web.bind.annotation.RestController;


/**
 * @Author: Leno
 * @Date: 2025-08-07
 * @Description: device接口
 */
@RequiredArgsConstructor
@Slf4j
@Tag(name = "device接口")
@RestController
@RequestMapping("/device")
public class DeviceController {

    private final IDeviceService deviceService;

    @Operation(summary = "查询所有Device")
    @GetMapping
    public Result<List<Device>> findAll() {
        return Result.success(deviceService.list());
    }

    @Operation(summary = "根据id查询Device")
    @GetMapping("/{id}")
    public Result<Device> findOne(@PathVariable Long id) {
        return Result.success(deviceService.getById(id));
    }

    @Operation(summary = "根据分页查询Device")
    @GetMapping("/page")
    public Result<Page<Device>> findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize, Device device) {
        return deviceService.findPage(pageNum, pageSize, device);
    }

    @Operation(summary = "添加或修改Device")
    @PostMapping
    public Result<Boolean> save(@RequestBody Device device) {
        return Result.success(deviceService.addOrUpdate(device));
    }

    @Operation(summary = "根据id批量删除Device")
    @DeleteMapping("/del/batch")
    public Result<String> deleteBatch(@RequestBody List<Long> ids) {
        return deviceService.deleteBatch(ids);
    }

}
